﻿using System;
using System.Collections.Generic;
using System.Xml;
using Assist;
using Autodesk.Revit.DB;
using YArchitech.Revit;
using YJKOpeningCommon.DataEnum;
using YJKOpeningCommon.OpeningEX;
using YJKOpeningCommon.OpeningProfile;
using YJKOpeningCommon.Public;

namespace YJKOpeningCommon.DbOpening
{
	public abstract class DbOpeningBase
	{
		public virtual bool CreateOpeningFamilyInstance(ViewScene ViewScene, out Element elem3D, out Element elem2D)
		{
			elem3D = null;
			elem2D = null;
			return true;
		}

		public bool GetOpeningXDataBase(ref OpeningXData objXData)
		{
			objXData.m_strDesignUser = this.m_strDesignUser;
			objXData.m_strCreateOpeningDate = this.m_strCreateOpeningDate;
			int num = (int)this.m_eSpeciality;
			string empty = string.Empty;
			if (StrSpecialityObj.m_strSpecialityObj.GetLength(0) > num)
			{
				objXData.m_strSpeciality = StrSpecialityObj.m_strSpecialityObj[num];
			}
			num = (int)this.m_eHostObject;
			string empty2 = string.Empty;
			if (StrHostObj.m_strHostObj.GetLength(0) > num)
			{
				objXData.m_strHostObject = StrHostObj.m_strHostObj[num];
			}
			objXData.m_directionProfile = this.m_profile.m_directionProfile;
			objXData.m_dHostWidth = this.m_dHostWidth;
			objXData.m_position = this.m_profile.m_position;
			objXData.m_strAxisX = this.m_strAxisX;
			objXData.m_strAxisY = this.m_strAxisY;
			objXData.m_strHostUniqueId = this.m_strHostUniqueId;
			return true;
		}

		public abstract bool CreateOpeningPreviewInstance(out Element elemPreview, PreViewScene preViewScene);

		public void SetCreateOpeningDate(string strCreateOpeningDate)
		{
			this.m_strCreateOpeningDate = strCreateOpeningDate;
		}

		public virtual void AddSharedParameters(Element elem)
		{
			Document document = elem.Document;
			List<string> list = new List<string>();
			list.Add(DbOpeningBase.m_strSharedParaOpeningMajor);
			list.Add(DbOpeningBase.m_strSharedParaOpeningSize);
			list.Add(DbOpeningBase.m_strSharedParaOpeningElevTop);
			list.Add(DbOpeningBase.m_strSharedParaOpeningElevCenter);
			list.Add(DbOpeningBase.m_strSharedParaOpeningElevBottom);
			list.Add(DbOpeningBase.m_strSharedParaOpeningElev);
            BuiltInCategory integerValue = (BuiltInCategory)elem.Category.Id.IntegerValue;
			Dictionary<string, ParameterType> dictionary = new Dictionary<string, ParameterType>();
			foreach (string text in list)
			{
				if (elem.GetParameter(text) == null)
				{
                    dictionary.Add(text, (ParameterType)1);
				}
			}
			if (dictionary.Count > 0)
			{
				SharedParameter.InsertSharedParameter(document, integerValue, "洞口信息", dictionary, false, true);
			}
		}

		public override bool Equals(object obj)
		{
			return this.m_strGuid.CompareTo(((DbOpeningBase)obj).m_strGuid) == 0;
		}

		public override int GetHashCode()
		{
			return this.m_strGuid.GetHashCode();
		}

		public virtual string GetCutSize(bool bIsFeet)
		{
			return this.m_profile.GetCutSize(bIsFeet);
		}

		public virtual string GetOpeningSize(bool bIsFeet)
		{
			return this.m_profile.GetOpeningSize(bIsFeet);
		}

		public virtual bool IsNeedCreateFamily()
		{
			return false;
		}

		public virtual bool Export2XmlNode(XmlElement xmlNode)
		{
			bool result;
			try
			{
				xmlNode.SetAttribute("OpeningClassName", base.GetType().Name);
				xmlNode.SetAttribute("strOpeningGuid", this.m_strGuid);
				xmlNode.SetAttribute("strHostGuid", this.m_strHostUniqueId);
				xmlNode.SetAttribute("strCutGuid", this.m_strCutUniqueId);
				xmlNode.SetAttribute("eHostObject", Convert.ToInt32(this.m_eHostObject).ToString());
				xmlNode.SetAttribute("eCutObject", Convert.ToInt32(this.m_eCutObject).ToString());
				xmlNode.SetAttribute("eOpeningObject", Convert.ToInt32(this.m_eSpeciality).ToString());
				xmlNode.SetAttribute("OpeningState", Convert.ToInt32(this.m_eOpeningState).ToString());
				xmlNode.SetAttribute("strAxisX", this.m_strAxisX);
				xmlNode.SetAttribute("strAxisY", this.m_strAxisY);
				xmlNode.SetAttribute("HostWidth", this.m_dHostWidth.ToString());
				xmlNode.SetAttribute("strFloorPlan", this.m_strFloorPlan);
				xmlNode.SetAttribute("strDesignDate", this.m_strDesignDate);
				xmlNode.SetAttribute("strRemark", this.m_strRemark);
				result = this.m_profile.Export2XmlNode(xmlNode);
			}
			catch
			{
				result = false;
			}
			return result;
		}

		public void SetDesignDate(string strDesignDate)
		{
			this.m_strDesignDate = strDesignDate;
		}

		public void SetDesignUser(string strDesignUser)
		{
			this.m_strDesignUser = strDesignUser;
		}

		public virtual bool ImportByXmlNode(XmlNode xmlNode)
		{
			try
			{
				this.m_strGuid = xmlNode.Attributes["strOpeningGuid"].Value;
				this.m_strHostUniqueId = xmlNode.Attributes["strHostGuid"].Value;
				this.m_strCutUniqueId = xmlNode.Attributes["strCutGuid"].Value;
				this.m_eHostObject = (EHostObject)Convert.ToInt32(xmlNode.Attributes["eHostObject"].Value);
				this.m_eCutObject = (ECutObject)Convert.ToInt32(xmlNode.Attributes["eCutObject"].Value);
				this.m_eSpeciality = (ESpeciality)Convert.ToInt32(xmlNode.Attributes["eOpeningObject"].Value);
				this.m_eOpeningState = (EOpeningState)Convert.ToInt32(xmlNode.Attributes["OpeningState"].Value);
				this.m_strAxisX = xmlNode.Attributes["strAxisX"].Value;
				this.m_strAxisY = xmlNode.Attributes["strAxisY"].Value;
				this.m_dHostWidth = Convert.ToDouble(xmlNode.Attributes["HostWidth"].Value);
				this.m_strFloorPlan = xmlNode.Attributes["strFloorPlan"].Value;
				this.m_strDesignDate = xmlNode.Attributes["strDesignDate"].Value;
				this.m_strRemark = xmlNode.Attributes["strRemark"].Value;
			}
			catch
			{
				return false;
			}
			return true;
		}

		public virtual string GetDimLabelItem(EDimItemType eDimItemTyppe)
		{
			return string.Empty;
		}

		public virtual void GetProfileOutLine3D(ref List<XYZ> lstOutLineView3DPt, ref Transform transform, bool isAddExtend, XYZ location = null)
		{
		}

		protected void TransformElev2Relative(ref double dElev, ref double dElevTop, ref double dElevBottom)
		{
			CommonInterface.TransformElev2Relative(DbOpeningBase.m_lstLevel, ref dElev);
			CommonInterface.TransformElev2Relative(DbOpeningBase.m_lstLevel, ref dElevTop);
			CommonInterface.TransformElev2Relative(DbOpeningBase.m_lstLevel, ref dElevBottom);
		}

		public static string m_strSharedParaOpeningMajor = "专业";

		public static string m_strSharedParaOpeningElevTop = "顶部标高";

		public static string m_strSharedParaOpeningElevCenter = "中心标高";

		public static string m_strSharedParaOpeningElevBottom = "底部标高";

		public static string m_strSharedParaOpeningElev = "标注标高";

		public static string m_strSharedParaOpeningSize = "尺寸";

		public static List<Level> m_lstLevel;

		public ElementId m_idModelGroup;

		public ECutObject m_eCutObject;

		public EHostObject m_eHostObject;

		public ESpeciality m_eSpeciality;

		public EOpeningState m_eOpeningState;

		public OpeningProfileBase m_profile;

		public string m_strCutUniqueId;

		public string m_strGuid;

		public string m_strHostUniqueId;

		public string m_strDesignDate;

		public string m_strDesignUser;

		public string m_strAxisX;

		public string m_strAxisY;

		public double m_dHostWidth;

		public string m_strFloorPlan;

		public string m_strRemark;

		public string m_strCreateOpeningDate;
	}
}
